package com.subject.shuati.application.mq;

import com.alibaba.fastjson.JSON;
import com.subject.shuati.domain.entity.SubjectLikedBo;
import com.subject.shuati.domain.service.SubjectLikedDomainService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@RocketMQMessageListener(topic = "subject-liked",consumerGroup = "subject-liked-consumer")
@Slf4j
public class SubjectLikedConsumer implements RocketMQListener<String>{
    @Resource
    private SubjectLikedDomainService subjectLikedDomainService;
    @Override
    public void onMessage(String s) {
        System.out.println("接收到点赞消费信息了,消息为："+s);
        SubjectLikedBo subjectLikedBo = JSON.parseObject(s, SubjectLikedBo.class);
        subjectLikedDomainService.syncLikedByMsg(subjectLikedBo);
    }
}
